# 10.05. 中等：一次编辑

class Solution:
    def oneEditAway(self, first: str, second: str) -> bool:
        if first == second or len(first) + len(second) == 1:
            return True
        if abs(len(first) - len(second)) > 1:
            return False

        if len(first) == len(second):
            i, j, t = 0, 0, 0
            while i < len(first) and j < len(second):
                if first[i] == second[j]:
                    i += 1
                    j += 1
                else:
                    t += 1
                    i += 1
                    j += 1
            if t > 1:
                return False
            else:
                return True

        if abs(len(first) - len(second)) == 1:
            i, j, t = 0, 0, 0
            while i < len(first) and j < len(second):
                if first[i] == second[j]:
                    i += 1
                    j += 1
                elif len(first) > len(second):
                    t += 1
                    i += 1
                elif len(first) < len(second):
                    t += 1
                    j += 1
            if t == 0:
                return True
            if t > 1 or i != len(first) or j != len(second):
                return False
            else:
                return True

